﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace NewKataminoSolver
{
    public partial class Katamino : Form
    {
        public Katamino()
        {
            InitializeComponent();
        }

        private void startButton_Click(object sender, EventArgs e)
        {

        }

        private void documentationButton_Click(object sender, EventArgs e)
        {
            // eerste acties:
            // create bitmap image (extra actie, picturebox public in Form1.Designer.cs voor toegang)
            Bitmap bm = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);

            // create graphics object from image
            Graphics g = Graphics.FromImage(bm);

            // bewerk graphics object, clear met een kleur
            g.Clear(Color.White);

            // bewaar in pictureBox (EN form!)
            pictureBox1.Image = bm;
            pictureBox1.Refresh();
            // this.Refresh();

            // herhaal vorige 2 stappen voor nog 2 andere kleuren na 1 seconden
            System.Threading.Thread.Sleep(500);
            g.Clear(Color.Gray);
            pictureBox1.Image = bm;
            pictureBox1.Refresh();

            System.Threading.Thread.Sleep(500);
            g.Clear(Color.Black);
            pictureBox1.Image = bm;
            pictureBox1.Refresh();

            KataminoGraph kg = new KataminoGraph(this, 72, 48);

            Penta[][] p = new Penta().Variations(); // in normalized form..

            for (int p1 = 0; p1 < p.Length; p1++)
            {
                for (int p2 = 0; p2 < p[p1].Length; p2++)
                {
                    kg.DrawColorPentaAt(p1 + 1, p[p1][p2], 6 * p1, 6 * p2);
                }
                kg.Refresh();
            }
            bm.Save(@"kataminos2.gif", System.Drawing.Imaging.ImageFormat.Gif);
            System.Threading.Thread.Sleep(500);

            // work towards solution
            // define backtracker template and try it with tester
            Debug.WriteLine("BackTrackerTester" + DateTime.Now.ToString("yyyy.MM.dd hh:mm:ss"));
            BackTrackerTester b = new BackTrackerTester(0, 0);

            foreach (BackTrackerTester r in b.Solve())
            {
            }

            KataminoBackTracker sg = new KataminoBackTracker(this, 12, 5);
            // draw the first penta to see if we have a new plot [Checked and OK]
            // sg.DrawColorPentaAt(1, p[0][0], 0, 0);
            // sg.Refresh();
            sg.Solve();

        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
